home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / SHADER / SHDR / CHECKER.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.3 KB  |  117 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: Checker.cpp 1.3 1997/04/11 01:21:39 damien Exp $ */
  3. //
  4. // Implementation of the Checker Shader
  5. //
  6.  
  7. #include "math.h"
  8.  
  9. #ifndef __CHECKER__
  10. #include "Checker.h"
  11. #endif
  12.  
  13. #ifndef __SHDRDLL__
  14. #include "Shdrdll.h"
  15. #endif
  16.  
  17. #undef INTERFACE
  18. #define INTERFACE CheckerShader
  19.  
  20. // Checker Constructor :
  21. CheckerShader::CheckerShader() {
  22.   CheckerPublicData.nbSquareU = CheckerPublicData.nbSquareV = 8;  // Default Value of the checker
  23.   };
  24.                         
  25. // Checker Destructor :
  26. CheckerShader::~CheckerShader() { 
  27.     global_count_Obj--; // used by the DLL to know if it can be unloaded
  28.                         // the variable is global and defines in "Shadrdll.cpp"
  29.     }                        
  30.  
  31. // How to Clone the Checker
  32. I3DExtension* CheckerShader::Clone(THIS) {
  33.   CheckerShader* theClone = new CheckerShader;  // Create New Checker
  34.   CopyData(theClone);                                                        // Copy Data in the new Checker
  35.   theClone->AddRef();
  36.   return theClone;
  37.   }
  38.   
  39. short CheckerShader::GetResID(THIS) {
  40.   return 128; // Ressource ID for the Shell
  41.   }
  42.  
  43. // Give a pointer to the public data that the shell can modify
  44. void* CheckerShader::GetExtensionDataBuffer(THIS) {
  45.   return ((void*) &(CheckerPublicData));
  46.   }                               
  47.   
  48. // Compare two Shader
  49. BOOLEAN CheckerShader::IsEqualTo(THIS_ I3DExShader* aShader) {
  50.   return ((CheckerPublicData.nbSquareU==((CheckerShader*)aShader)->CheckerPublicData.nbSquareU)
  51.           && (CheckerPublicData.nbSquareV==((CheckerShader*)aShader)->CheckerPublicData.nbSquareV)); 
  52.   }                                                                                                     
  53.   
  54. BOOLEAN CheckerShader::DependsOnAppliedExtent(THIS) {
  55.   return TRUE; // The Checker uses the UV Space coordinate
  56.   }
  57.   
  58. HRESULT CheckerShader::DoShade(THIS_ ShadingInOut* /*theShadingIO*/, ShadingElem* /*theShadingElem*/)    {
  59.   return ResultFromScode(E_NOTIMPL);
  60.   }
  61.                   
  62. #define MyEven(xx)    (!(((long)(xx)) & 0x00000001)) // to know if xx is Even or Odd
  63.  
  64. ULONG CheckerShader::GetPreferredOutput(THIS) {
  65.   return kUsesGetValue; // Tell the Shell that this Shader returns a Value
  66.   }                    
  67.   
  68. HRESULT CheckerShader::GetValue(THIS_ NUM3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
  69.   if (!fPreprocessed) { // Coefficient factors is not already calculated
  70.     fMul[0]= ((NUM3D)CheckerPublicData.nbSquareU) / (theShadingElem->fShaderBox.fRight - theShadingElem->fShaderBox.fLeft);
  71.     fMul[1]= ((NUM3D)CheckerPublicData.nbSquareV) / (theShadingElem->fShaderBox.fTop - theShadingElem->fShaderBox.fBottom);
  72.     fPreprocessed = TRUE;
  73.     }
  74.   NUM3D nu = (theShadingIn->fUV[0]-theShadingElem->fShaderBox.fLeft) * fMul[0];
  75.   NUM3D nv = (theShadingIn->fUV[1]-theShadingElem->fShaderBox.fBottom) * fMul[1];
  76.   if (MyEven(floor(nu) + floor(nv))) {
  77.     *result = 0.0;
  78.     }
  79.   else {
  80.       *result = 1.0;
  81.       }
  82.   return NOERROR;
  83.   }
  84.                      
  85. // You must create these functions to create an non-abstract Object                     
  86. HRESULT CheckerShader::GetColor(THIS_ COLOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem)    {
  87.   return ResultFromScode(E_NOTIMPL);
  88.   }
  89.  
  90. HRESULT CheckerShader::GetVector(THIS_ VECTOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
  91.     return ResultFromScode(E_NOTIMPL);
  92.     }
  93.  
  94. // Set the flags of the Shader
  95. HRESULT CheckerShader::GetShadingFlags(THIS_ ShadingFlags* theFlags)    {
  96.   theFlags->fNeedsUV  = TRUE;
  97.   theFlags->fCallOnce = FALSE;
  98.   return NOERROR;
  99.   }
  100.                               
  101. // Function to Clone the Object
  102. void CheckerShader::CopyData(COMShader* dest) {
  103.   COMShader::CopyData(dest); // Copy Data of the inherited object (Shader)
  104.   ((CheckerShader*)dest)->CheckerPublicData=CheckerPublicData; // Copy Public Data
  105.   ((CheckerShader*)dest)->fMul[0]=fMul[0];
  106.   ((CheckerShader*)dest)->fMul[1]=fMul[1]; // Copy Preprocessed Data
  107.   }
  108.                                                               
  109. // If you don't use a ressource that can give the type of the different
  110. // data in the CheckerShaderPublicData you have to give a pointer on this
  111. // Properties Map
  112. ExtensionDataMap* CheckerShader::GetExtensionDataMap(THIS) {
  113.   return NULL;
  114.   }
  115.   
  116.  
  117.